package com.iss.ssm0531;

import com.iss.ssm0531.dao.UserDAO;
import com.iss.ssm0531.dao.provider.UserProvider;
import com.iss.ssm0531.model.User;
import org.apache.ibatis.annotations.UpdateProvider;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.HashMap;
import java.util.List;

/*测试注解版的mybatis的相关功能*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Ssm0531Application.class)
public class UserDAOTest2 {

    @Autowired
    private UserDAO userDAO;

    @Test
    public void testSelectAll(){
      List<User> userList= userDAO.selectAll();
      for (User user : userList){
          System.out.println("username:"+user.getUsername());
          System.out.println("password:"+user.getPassword());
      }
    }

    @Test
    public void testSelectByPrimary(){
        userDAO.selectByPrimary(5);
    }


    @Test
    public void testSelectByExamle(){
        User user = new User();
        user.setUsername("dev");
        user.setPassword("123456");
        userDAO.selectByExample(user);
    }

    @Test
    public void testSelectByMap(){
        HashMap map = new HashMap();
        map.put("username","dev");
        map.put("password","123");
        userDAO.selectByMap(map);
    }

    @Test
    public void testSelectByMultiple(){
        User user = new User();
       // user.setUsername("dev");
        user.setPassword("123456");
        userDAO.selectByMutiple(user);
    }

    @Test
    public void testUpdateProvider(){
        UserProvider provider = new UserProvider();
        User user = new User();
        user.setUsername("dev2");
        user.setPassword("123");
        user.setUserId(5);
         userDAO.updateUser(user);
    }
}
